package com.xh.petdogexpert.user.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xh.petdogexpert.base.BaseController;
import com.xh.petdogexpert.base.BaseException;
import com.xh.petdogexpert.base.ResponseData;
import com.xh.petdogexpert.sys.service.ILoginService;
import com.xh.petdogexpert.user.dto.User;

@Controller
@RequestMapping(value = "/login/")
public class LoginController extends BaseController {

	@Autowired
	ILoginService loginService;

	@RequestMapping(value = "inhome")
	@ResponseBody
	public ResponseData loginHome(HttpServletRequest  request, User user) throws BaseException {

		boolean ok = loginService.login(user);
		if (ok) {
			return new ResponseData(request.getContextPath() + "/web-cilent/containhtml.html");
		}
		return null;
	}
	
	@RequestMapping(value = "in")
	@ResponseBody
	public ResponseData login(HttpServletRequest  request, User user) throws BaseException {

		boolean ok = loginService.login(user);
		if (ok) {
			return new ResponseData(request.getContextPath() + "/");
		}
		return null;
	}

	@RequestMapping(value = "out")
	@ResponseBody
	public ModelAndView logout() throws BaseException {

		boolean ok = loginService.logout();
		if (ok) {
			return new ModelAndView("redirect:/login.html");
		}
		return null;
	}
	@RequestMapping(value = "ss")
	@ResponseBody
	public ModelAndView homeout() throws BaseException {

		boolean ok = loginService.logout();
		if (ok) {
			return new ModelAndView("redirect:/web-cilent/Qlogin.html");
		}
		return null;
	}
}
